﻿using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class QueueShowTip : MonoBehaviour
{
    // Start is called before the first frame update
    Queue<string> showQueue = new Queue<string>();
    //显示间隔时间
    public float stepTime = 2;
    public Text text;
    DOTweenAnimation tweenAnimation;
    private void Awake()
    {
        tweenAnimation = GetComponent<DOTweenAnimation>();
        text = GetComponent<Text>();
        tweenAnimation.onComplete.AddListener(EndPlay);
        tweenAnimation.DOKill(false);
    }
    void Start()
    {
        SaveGame.onSaveSuccessful.AddListener(SaveGameShowTip);
        InvokeRepeating("ShowTip",0,stepTime);
    }

    public void ShowTip()
    {
       
        if (showQueue.Count>0)
        {
            text.color = Color.white;
            text.text= showQueue.Dequeue();
            tweenAnimation.DORestart();
        }
        else
        {
            tweenAnimation.DOPause();
        }
    }

    public void EndPlay()
    {
        text.text = "";
    }


    private void SaveGameShowTip()
    {
        showQueue.Enqueue("保存成功");
    }

    public void OnDisable()
    {
        SaveGame.onSaveSuccessful.RemoveListener(SaveGameShowTip);
    }
}
